﻿using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace ADEVSO.Drawing.Graphics
{
    public struct GraphicsSettings
    {
        public CompositingMode CompositingMode;
        public CompositingQuality CompositingQuality;
        public InterpolationMode InterpolationMode;
        public PixelFormat PixelFormat;
        public PixelOffsetMode PixelOffsetMode;
        public SmoothingMode SmoothingMode;
        public int Resolution;

        /// <summary>
        /// Create graphics settings as medium quality
        /// </summary>
        /// <returns></returns>
        public static GraphicsSettings New()
        {
            return New(GraphicsQuality.Medium);
        }

        /// <summary>
        /// Create graphics settings as custom quality
        /// </summary>
        /// <param name="quality"></param>
        /// <returns></returns>
        public static GraphicsSettings New(GraphicsQuality quality)
        {
            switch (quality)
            {
                case (GraphicsQuality.Low):
                    {
                        return InitLow();
                    }
                case (GraphicsQuality.Medium):
                    {
                        return InitMedium();
                    }
                case (GraphicsQuality.High):
                    {
                        return InitHigh();
                    }
                default:
                    return InitMedium();
            }
        }

        private static GraphicsSettings InitLow()
        {
            GraphicsSettings result = new GraphicsSettings
            {
                CompositingMode = CompositingMode.SourceOver,
                CompositingQuality = CompositingQuality.HighSpeed,
                InterpolationMode = InterpolationMode.High,
                PixelFormat = PixelFormat.Format16bppRgb565,
                PixelOffsetMode = PixelOffsetMode.HighSpeed,
                Resolution = 70,
                SmoothingMode = SmoothingMode.HighSpeed
            };
            return result;
        }

        private static GraphicsSettings InitMedium()
        {
            GraphicsSettings result = new GraphicsSettings
            {
                CompositingMode = CompositingMode.SourceCopy,
                CompositingQuality = CompositingQuality.HighQuality,
                InterpolationMode = InterpolationMode.HighQualityBilinear,
                PixelFormat = PixelFormat.Format24bppRgb,
                PixelOffsetMode = PixelOffsetMode.Half,
                Resolution = 85,
                SmoothingMode = SmoothingMode.HighQuality
            };
            return result;
        }

        private static GraphicsSettings InitHigh()
        {
            GraphicsSettings result = new GraphicsSettings
            {
                CompositingMode = CompositingMode.SourceCopy,
                CompositingQuality = CompositingQuality.HighQuality,
                InterpolationMode = InterpolationMode.HighQualityBicubic,
                PixelFormat = PixelFormat.Format32bppRgb,
                PixelOffsetMode = PixelOffsetMode.HighQuality,
                Resolution = 100,
                SmoothingMode = SmoothingMode.HighQuality
            };
            return result;
        }
    }
}
